<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="shortcut icon" href="../static/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../static/css/reset.css" />
    <link rel="stylesheet" type="text/css" href="../static/css/register.css" />
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script>
        $(function () {
            $('#username').on('blur', function () {
                $.ajax({
                    url: '/register',
                    type: 'post',
                    data: {
                        username: $('#username').val(),
                    },
                    success(res) {
                        $('.tips').eq(0).html(res)
                    }
                })
            })
            $('#password').on('blur', function () {
                $.ajax({
                    url: '/register',
                    type: 'post',
                    data: {
                        password: $('#password').val(),
                        password1: $('#password1').val(),
                    },
                    success(res) {
                        if (res == '俩次密码输入不一致 请重新输入') {
                            $('.tips').eq(2).html(res)
                        } else {
                            $('.tips').eq(2).html('')
                        }

                        if ($('#password').val() == '') {
                            $('.tips').eq(1).html(res)
                        } else {
                            $('.tips').eq(1).html('')
                        }
                    }
                })
            })

            $('#password1').on('blur', function () {
                $.ajax({
                    url: '/register',
                    type: 'post',
                    data: {
                        password: $('#password').val(),
                        password1: $('#password1').val(),
                    },
                    success(res) {
                        if ($('#password1').val() == '') {
                            $('.tips').eq(2).html(res)
                        } else {
                            $('.tips').eq(2).html('')
                        }

                        if (res == '俩次密码输入不一致 请重新输入') {
                            $('.tips').eq(2).html(res)
                        } else {
                            $('.tips').eq(2).html('')
                        }

                    }
                })
            })

            $('.loginbtn').on('click', () => {
                $.ajax({
                    url: '/register',
                    type: 'post',
                    data: {
                        username: $('#username').val(),
                        password: $('#password').val(),
                        password1: $('#password1').val()
                    },
                    success(res) {
                        console.log(res);
                        if (res == '✔') {
                            alert('注册成功')
                            $('input').val(''),
                                $('.tips').html('')
                        } else {
                            alert('请确认后再试')
                        }
                    }
                })
            })
        })
    </script>
</head>

<body>
    <div class="pos">
        <div class="login">
            <span class="close iconfont icon-close"></span>
            <img src="../static/img/login/loginlogo.png" alt="">
            <ul>
                <li></li>
                <li class="phone">使用手机号登陆</li>
                <li></li>
            </ul>

            <!-- <form action="/register" method="POST"> -->
            <input style="margin-top: 0;" type="text" name="username" id="username" placeholder="请输入您的手机号">
            <span class="tips"></span>
            <input type="password" id="password" placeholder="请输入密码" name="password">
            <span class="tips"></span>
            <input type="password" id="password1" placeholder="请再次输入密码" name="password1">
            <span class="tips"></span>
            <div class="clear"></div>
            <button class="loginbtn">注册</button>
            <!-- </form> -->

            <p>
                <input type="checkbox" class="xuanze" />
                <span><a href="javascript:;">我同意 《用户使用协议》</a></span>
                <span>
                    已有账号
                    <a href="javascript:;">去登陆</a>
                </span>
            </p>
        </div>
    </div>
    <!-- <script src="../static/utils/utils.js"></script> -->

</body>

</html>